/**
 *
 * Copyright 2010 TeleNav, Inc. All rights reserved.
 * EntryModel.java
 *
 */
package com.telenav.module.home;

import org.jivesoftware.smack.packet.Presence;

import com.telenav.framework.mvc.AbstractModel;
import com.telenav.xmpp.XmppTool;

class HomeModel extends AbstractModel implements IHomeConstants
{  
	@Override
	protected void doAction(int actionId) {
        switch (actionId)
        {
            case ACTION_INIT:
            {
                break;
            }
            case ACTION_LOGIN:
            {
        		new Thread(new Runnable()
        		{
        			public void run()
        			{
        				login(getString(KEY_S_USERNAME), getString(KEY_S_PWD));
        			}
        		}).start();
            	break;
            }
        }
	}
	
    private void login(String username, String password)
    {
    	try {
    		XmppTool.getConnection().login(username, password);
    		
			Presence presence = new Presence(Presence.Type.available);
			XmppTool.getConnection().sendPacket(presence);
			//DaoManager.getInstance().getAccountDao().setAccount(username, password);
			//if(!DaoManager.getInstance().getAccountDao().isRegister())
			//{
				//cloud();
				//DaoManager.getInstance().getAccountDao().setIsRegister(true);
			//}
			postModelEvent(EVENT_MODEL_LOGIN_SUCCESS);
		} catch (Exception e) {
			XmppTool.closeConnection();
			//DaoManager.getInstance().getAccountDao().setAccount(null, null);
			//Toast.makeText(LoginActivity.this, "login failure", 0).show();
		}
    }
}
